import defaultSettings from '@/settings'
import Cookies from 'js-cookie'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  theme: Cookies.get('theme') || '#409EFF' // 这里注意 这里只能用十六进制 或者是rgb格式 不能直接使用red
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  },
  // 切换颜色时 设置vuex theme数据
  setTheme(state, theme) {
    state.theme = theme
    Cookies.set('theme', theme)
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

